package com.glela.api.upload.qiniu.http;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.httpclient.NameValuePair;

public class HttpRequest
{

	/** HTTP GET method */
	public static final String METHOD_GET = "GET";

	/** HTTP POST method */
	public static final String METHOD_POST = "POST";

	/**
	 * 待请求的url
	 */
	private String url = null;
	Map<String, String> heads = new HashMap<String, String>();
	/**
	 * 默认的请求方式
	 */
	private String method = METHOD_POST;

	private int timeout = 0;

	private int connectionTimeout = 0;

	/**
	 * Post方式请求时组装好的参数值对
	 */
	private List<NameValuePair> parameters = null;

	/**
	 * InputStream内容
	 */
	private String requestBody = null;
	/**
	 * Get方式请求时对应的参数
	 */
	private String queryString = null;

	/**
	 * 默认的请求编码方式
	 */
	private String charset = "GBK";

	/**
	 * 请求发起方的ip地址
	 */
	private String clientIp;

	/**
	 * 请求返回的方式
	 */
	private HttpResultType resultType = HttpResultType.BYTES;

	public HttpRequest(HttpResultType resultType)
	{
		super();
		this.resultType = resultType;
	}

	/**
	 * @return Returns the charset.
	 */
	public String getCharset()
	{
		return charset;
	}

	/**
	 * @return Returns the clientIp.
	 */
	public String getClientIp()
	{
		return clientIp;
	}

	public int getConnectionTimeout()
	{
		return connectionTimeout;
	}

	public Map<String, String> getHeads()
	{
		return heads;
	}

	public String getMethod()
	{
		return method;
	}

	public List<NameValuePair> getParameters()
	{
		return parameters;
	}

	public String getQueryString()
	{
		return queryString;
	}

	public String getRequestBody()
	{
		return requestBody;
	}

	public HttpResultType getResultType()
	{
		return resultType;
	}

	public int getTimeout()
	{
		return timeout;
	}

	public String getUrl()
	{
		return url;
	}

	/**
	 * @param charset
	 *            The charset to set.
	 */
	public void setCharset(String charset)
	{
		this.charset = charset;
	}

	/**
	 * @param clientIp
	 *            The clientIp to set.
	 */
	public void setClientIp(String clientIp)
	{
		this.clientIp = clientIp;
	}

	public void setConnectionTimeout(int connectionTimeout)
	{
		this.connectionTimeout = connectionTimeout;
	}

	public void setHead(String string, String string2)
	{
		heads.put(string, string2);
	}

	public void setHeads(Map<String, String> heads)
	{
		this.heads = heads;
	}

	public void setMethod(String method)
	{
		this.method = method;
	}

	public void setParameters(List<NameValuePair> parameters)
	{
		this.parameters = parameters;
	}

	public void setQueryString(String queryString)
	{
		this.queryString = queryString;
	}

	public void setRequestBody(String requestBody)
	{
		this.requestBody = requestBody;
	}

	public void setResultType(HttpResultType resultType)
	{
		this.resultType = resultType;
	}

	public void setTimeout(int timeout)
	{
		this.timeout = timeout;
	}

	public void setUrl(String url)
	{
		this.url = url;
	}

}
